home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
70
/
examples
/
examples.arc
/
PRIMES.ST
< prev
next >
Wrap
Text File
|
1985-11-20
|
654b
|
37 lines
Class Main
[
main
(Primes new) do: [:x | x print]
]
Class Primes
| primeGenerator lastFactor |
[
first
primeGenerator <- 2 to: 300.
lastFactor <- primeGenerator first.
^ lastFactor
|
next
primeGenerator <- (Factor new ;
remove: lastFactor
from: primeGenerator ).
^ lastFactor <- primeGenerator next.
]
Class Factor
| myFactor generator |
[
remove: factorValue from: generatorValue
myFactor <- factorValue.
generator <- generatorValue
|
next | possible |
[(possible <- generator next) notNil]
whileTrue:
[(possible \\ myFactor ~= 0)
ifTrue: [ ^ possible] ].
^ nil
]